package net.siufung.market.base.user.controller.regulation;

import lombok.AllArgsConstructor;
import net.siufung.core.exception.BizServiceException;
import net.siufung.core.model.VerifyRepeatDto;
import net.siufung.core.model.enums.MethodEventEnum;
import net.siufung.core.model.regulation.AbstractRegulation;
import net.siufung.market.base.user.controller.model.dto.UserPostUpdateDto;
import net.siufung.market.base.user.mapper.IUserPostMapper;

/**
 * @author 陈建峰
 * @date 2023/2/7 1:36 PM
 * @since V1.0.0
 */
@AllArgsConstructor
public class UserPostUpdateRegulation extends AbstractRegulation<UserPostUpdateDto> {

    private static final long serialVersionUID = -1822857988644509604L;

    private final IUserPostMapper userPostMapper;

    @Override
    public boolean isSatisfiedBy(UserPostUpdateDto userPostUpdateDto) {
        VerifyRepeatDto<Integer> verifyRepeatDto = new VerifyRepeatDto<>();
        verifyRepeatDto.setMethodEventEnum(MethodEventEnum.UPDATE);
        verifyRepeatDto.setPk(userPostUpdateDto.getId());
        verifyRepeatDto.setVerifyKeyValue(userPostUpdateDto.getPostName());
        if(!userPostMapper.checkPostNameNotRepeat(verifyRepeatDto)){
            throw new BizServiceException("用户岗位名称重复！");
        }
        return Boolean.TRUE;
    }
}
